package com.sfdk.graphics.core {
    import com.sfdk.data.api.ITreeDataProvider;
    import com.sfdk.io.GenericIO;
    import com.sfdk.pools.BitmapDataPool;

    import flash.display.BitmapData;

    import flash.events.Event;

    public class BitmapEx extends GenericIO implements ITreeDataProvider {

        public function BitmapEx(currentDirectory : String = null, filePath : String = null)
		{

            _fullName = filePath;
			if(filePath != null)
			{
				var pathArray : Array = filePath.split("/");
				_type = pathArray[pathArray.length - 2];
				_rootType = pathArray[1];
				_name = pathArray[pathArray.length - 1];
			}

		    super(currentDirectory+filePath, GenericIO.BITMAP_FILE);
		}

        private var _fullName:String;
		private var _name:String;
		private var _type:String;
		private var _rootType:String;

		public function get fullName():String
		{
			return _fullName;
		}

		public function set fullName(value:String):void
		{
			_fullName = value;
		}

		public function get label():String
		{
			return _name;
		}

		public function set name(value:String):void
		{
			_name = value;
		}

		public function get type():String
		{
			return _type;
		}

		public function get rootType():String
		{
			return _rootType;
		}

        public function get isImage():Boolean {
            return true;
        }

        public function get imageData():BitmapData {
            return getImageData();
        }

        protected var _isLoaded:Boolean = false;

        public function get isLoaded():Boolean {
            return _isLoaded;
        }

        override protected function init():void {
            super.init();
            BitmapDataPool.instance.addToPool(this.getImageData(), _fileLocation);

            dispatchEvent(new Event("bitmapExLoaded"));
            _isLoaded = true;
        }
    }
}